<!--
 * @Author: your name
 * @Date: 2022-04-17 11:59:20
 * @LastEditTime: 2022-04-17 12:23:54
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\4.17.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
 * @param {string} paragraph
 * @param {string[]} banned
 * @return {string}
 */
        var mostCommonWord = function (paragraph, banned) {
            let wordmap = new Map();
            paragraph = paragraph.toLowerCase();
            let newstr = '';
            for (let i = 0; i < paragraph.length; i++) {
                if (paragraph[i].charCodeAt() < 97 || paragraph[i].charCodeAt() > 122) {
                    newstr += ' ';
                } else {
                    newstr += paragraph[i];
                }
            }
            newstr = newstr.split(' ');
            for (let i = 0; i < newstr.length; i++) {
                if (!newstr[i]) continue;
                if (wordmap.has(newstr[i])) {
                    wordmap.set(newstr[i], wordmap.get(newstr[i]) + 1);
                } else {
                    wordmap.set(newstr[i], 1);
                }
            }
            for (let i = 0; i < banned.length; i++) {
                wordmap.delete(banned[i]);
            }
            let result, max = 0;
            for (const [key, value] of wordmap.entries()) {
                if (value >= max) {
                    result = key;
                    max = value;
                }
            }
            return result;
        };
        console.log(mostCommonWord("A, a, a, a, b,b,b,c, c", ["a"]));
    </script>
</body>

</html>